package top.sky.log.config;

import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.sky.log.listener.MDCListener;

/**
 * Register location listener config.
 *
 * @author shijin.liu
 * @see MDCListener
 * @since 2023-07-01
 */
@Configuration
public class MDCListenerConfig {

    public MDCListenerConfig() {
        System.out.println(" ___            __        ___    ___  __        __                __   __   __          __  \n" +
                "|__  |\\ |  /\\  |__) |    |__      |  |__)  /\\  /  ` |__/    |    /  \\ / _` / _` | |\\ | / _` \n" +
                "|___ | \\| /~~\\ |__) |___ |___     |  |  \\ /~~\\ \\__, |  \\    |___ \\__/ \\__> \\__> | | \\| \\__> \n"
                +"                                                                                                 "
        );
    }

    /**
     * Register location context listener.
     *
     * @return The {@link ServletListenerRegistrationBean} bean.
     */
    @Bean("MDCListener")
    public ServletListenerRegistrationBean servletListenerRegistrationBean() {
        return new ServletListenerRegistrationBean(new MDCListener());
    }
}
